package sng.modules.view.components.city.logic.unit
{
	import core.interfaces.IDispose;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;

	/*
	 *连续拾取奖励动画类 royjin 20110714 
	*/
	public final class Bonus extends Sprite implements IDispose
	{
		private var skin:SwfSheet;
		private var stopFrame:int;
		private var state:int;			//状态,0是未启动,1是播放中,2是等待关闭中
		private var timeID:int;		//隐藏倒计时ID
		
		public function Bonus()
		{
			super();
			skin = new SwfSheet("assets/flash/bonus.swf",1)
			this.skin.visible = false;
			this.addChild(this.skin);
			
			state = 0;
		}
		public function dispose():void
		{
			//state = 0;
			//this.ReSet();
		}
		public function Hide():void
		{	
			this.state = 0;
			flash.utils.clearTimeout(this.timeID);
			this.skin.visible = false;
			skin.mc.gotoAndStop(0);
		}
		public function AddBonus(count:int=20):void
		{
			if(state==0)
			{
				stopFrame = count;
				
				skin.visible = true;
				skin.mc.addEventListener(Event.ENTER_FRAME,OnEnterFrame,false,0,true);
				
				skin.mc.play();
				state=1;
				
			}
			else if(state==1)
			{
				stopFrame+=count;
				if(stopFrame>=100){stopFrame=100;}
			}
			else if(state==2)
			{
				stopFrame+=count;
				if(stopFrame>=100){stopFrame=100;}
				skin.mc.addEventListener(Event.ENTER_FRAME,OnEnterFrame,false,0,true);
				skin.mc.play();
				state=1;
				flash.utils.clearTimeout(this.timeID);
			}
		}
		
		protected function OnEnterFrame(event:Event):void
		{
			if(skin.mc.currentFrame>=stopFrame)
			{
				state=2;
				skin.mc.removeEventListener(Event.ENTER_FRAME,OnEnterFrame);
				this.skin.mc.stop();
				
				this.timeID = flash.utils.setTimeout(Hide,2000);
			}

		}
	}
}